public class BalancePro {
    public boolean isBalanced(TreeNode root) {
        if (root == null) {
            return true;
        }
        return high(root) > 0;
    }


    private int high(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int left = high(root.left);
        int right = high(root.right);
        if (left >= 0 && right >= 0 && Math.abs(left - right) <= 1) {
            return left > right ? left + 1 : right + 1;
        } else {
            //此时已经发现有子树不是平衡二叉树
            return -1;
        }
    }
}
